// ip字符串转整数
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char ip[] = "192.168.0.100";
    char *p = ip;
    char *p1 = p;
    char buf[4];
    unsigned int uip = 0;
    int i = 0;
    while (p1 != NULL)
    {
        memset(buf, 0, sizeof(buf));
        p1 = strstr(p, ".");
        if (p1 == NULL)
            strcpy(buf, p);
        else
            memcpy(buf, p, p1 - p);
        uip = uip + (atoi(buf) << (24 - i * 8));
        p = p1 + 1;
        i++;
    }

    printf("uip=%x\n", uip);
    //结果: uip = c0a80064
    //若没有memset(buf,0,sizeof(buf));则输出为: uip = c0a84464
    
    return 0;
}
